package cn.com.agameofthrones.AGoTLCGCards.Fragment;

import cn.com.agameofthrones.AGoTLCGCards.AGoTContentProvider;
import cn.com.agameofthrones.AGoTLCGCards.R;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

public class SingleCardActivity extends FragmentActivity {
	private ViewPager mCardsPager;
	private static Cursor mIDCursor;
	 @Override
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.single_card_pager);
	        mCardsPager = (ViewPager)findViewById(R.id.cards_pager);
	        mCardsPager.setId(R.id.cards_pager);
	        mCardsPager.setAdapter(new CardsAdapter(getSupportFragmentManager()));
	        
	        String where_clause=getIntent().getStringExtra(
            		"cn.com.agameofthrones.AGoTLCGCards.search_sql");
	        mIDCursor=this.managedQuery(
            		AGoTContentProvider.SEARCH_CARDS_URI, new String[]{"_id"}, where_clause, null, null);
	        int current_item=getIntent().getIntExtra(
            		"cn.com.agameofthrones.AGoTLCGCards.current_position",0);
	        mCardsPager.setCurrentItem(current_item);
	 }
	 
	 public static class CardsAdapter extends FragmentStatePagerAdapter{

		public CardsAdapter(FragmentManager fm) {
			super(fm);
			// TODO Auto-generated constructor stub
		}

		@Override
		public Fragment getItem(int position) {
			// TODO Auto-generated method stub
			mIDCursor.moveToPosition(position);
			return new SingleCardFragment(mIDCursor.getString(0));
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mIDCursor.getCount();
		}
		   
	   }

}
